Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.ComponentModel

Namespace BillingNetControlLibrary

    <Serializable(), DefaultProperty("Text"), ToolboxData("<{0}:ContentPaneFooter runat=server></{0}:ContentPaneFooter>"), _
    System.ComponentModel.Designer("System.Web.UI.Design.WebControls.TableDesigner, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")> _
    Public Class ContentPaneFooter
        Inherits System.Web.UI.WebControls.Table
        Implements IPostBackDataHandler

        <EditorBrowsable(EditorBrowsableState.Always), Browsable(True)> _
        Public Event Confirmed As EventHandler
        Public Event NavigateBack As EventHandler
        Private btnConfirm As Button
        Private btnNavigateBack As Button

        <Bindable(True), Category("Behavior"), DefaultValue(True)> _
        Public Property CausesValidation() As Boolean
            Get
                If Me.ViewState("__causesValidation") = Nothing Then
                    Return True
                Else
                    Return CBool(Me.ViewState("__causesValidation"))
                End If
            End Get
            Set(ByVal Value As Boolean)
                Me.ViewState("__causesValidation") = Value
            End Set
        End Property

        <Bindable(True), Category("Appearance"), DefaultValue(True)> _
        Public Property NavigateBackVisible() As Boolean
            Get
                If Me.ViewState("__navigateBackVisible") = Nothing Then
                    Return True
                Else
                    Return CBool(Me.ViewState("__navigateBackVisible"))
                End If
            End Get
            Set(ByVal Value As Boolean)
                Me.ViewState("__navigateBackVisible") = Value
            End Set
        End Property

        <Bindable(True), Category("Appearance"), DefaultValue("")> _
        Public Property ButtonsCssClass() As String
            Get
                If Me.ViewState("__buttonsCssClass") = Nothing Then
                    Return ""
                Else
                    Return CType(Me.ViewState("__buttonsCssClass"), String)
                End If
            End Get
            Set(ByVal Value As String)
                Me.ViewState("__buttonsCssClass") = Value
            End Set
        End Property

        <Bindable(True), Category("Appearance"), DefaultValue("")> _
        Public Property NavigateBackText() As String
            Get
                If Me.ViewState("__navigateBackText") = Nothing Then
                    Return ""
                Else
                    Return CType(Me.ViewState("__navigateBackText"), String)
                End If
            End Get
            Set(ByVal Value As String)
                Me.ViewState("__navigateBackText") = Value
            End Set
        End Property

        <Bindable(True), Category("Appearance"), DefaultValue("")> _
        Public Property NavigateBackClientFunction() As String
            Get
                If Me.ViewState("__navigateBackClientFunction") = Nothing Then
                    Return ""
                Else
                    Return CType(Me.ViewState("__navigateBackClientFunction"), String)
                End If
            End Get
            Set(ByVal Value As String)
                Me.ViewState("__navigateBackClientFunction") = Value
            End Set
        End Property

        <Bindable(True), Category("Appearance"), DefaultValue("")> _
        Public Property ConfirmText() As String
            Get
                If Me.ViewState("__confirmText") = Nothing Then
                    Return ""
                Else
                    Return CType(Me.ViewState("__confirmText"), String)
                End If
            End Get
            Set(ByVal Value As String)
                Me.ViewState("__confirmText") = Value
            End Set
        End Property

        <Bindable(True), Category("Appearance"), DefaultValue("")> _
        Public Property ConfirmClientFunction() As String
            Get
                If Me.ViewState("__confirmClientFunction") = Nothing Then
                    Return ""
                Else
                    Return CType(Me.ViewState("__confirmClientFunction"), String)
                End If
            End Get
            Set(ByVal Value As String)
                Me.ViewState("__confirmClientFunction") = Value
            End Set
        End Property

        Public Property ConfirmButton() As Button
            Get
                If btnConfirm Is Nothing Then
                    btnConfirm = New Button
                    btnConfirm.ID = "btnConfirm"
                    btnConfirm.Text = Me.ConfirmText
                    btnConfirm.Attributes("class") = Me.ButtonsCssClass
                    btnConfirm.CausesValidation = Me.CausesValidation
                    'btnConfirm.Attributes["onclick"] = this.Page.GetPostBackEventReference(btnConfirm, "");
                End If
                Return btnConfirm
            End Get
            Set(ByVal Value As Button)
                btnConfirm = Value
            End Set
        End Property

        Private Property NavigateBackButton() As Button
            Get
                If btnNavigateBack Is Nothing Then
                    btnNavigateBack = New Button
                    btnNavigateBack.ID = "btnNavigateBack"
                    btnNavigateBack.Text = Me.NavigateBackText
                    btnNavigateBack.Attributes("class") = Me.ButtonsCssClass
                    btnNavigateBack.CausesValidation = False
                End If
                Return btnNavigateBack
            End Get
            Set(ByVal Value As Button)
                btnNavigateBack = Value
            End Set
        End Property


        Protected Overrides Sub OnInit(ByVal e As EventArgs)
            If Me.ViewState("__navigateBackClientFunction") Is Nothing Then
                Me.ViewState("__navigateBackClientFunction") = "javascript:history.back()"
            End If
            MyBase.OnInit(e)
        End Sub

        Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
            Me.Page.RegisterRequiresPostBack(Me)
            MyBase.OnPreRender(e)
        End Sub

        Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
            Me.Rows.Add(New TableRow)
            Me.Rows(0).Cells.AddRange(New TableCell() {New TableCell, New TableCell})
            Me.Rows(0).Cells(0).Controls.Add(Choose(Math.Abs(CInt(Me.NavigateBackVisible)) + 1, New LiteralControl("&nbsp"), Me.NavigateBackButton))
            Me.Rows(0).Cells(1).Controls.Add(Me.ConfirmButton)
            Me.Rows(0).Cells(1).HorizontalAlign = HorizontalAlign.Right
            If Me.ConfirmedEvent Is Nothing Then
                Me.ConfirmButton.Attributes("onclick") = Me.ConfirmClientFunction + ";return false;"
            End If
            If Me.NavigateBackEvent Is Nothing Then
                Me.NavigateBackButton.Attributes("type") = "button"
                Me.NavigateBackButton.Attributes("onclick") = Me.NavigateBackClientFunction + ";return false;"
            End If
            MyBase.Render(output)
        End Sub


        Public Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NameValueCollection) As Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData
            If postDataKey = Me.ClientID Then
                If Not (postCollection(Me.ConfirmButton.ClientID) Is Nothing And Me.Events.Item("Confirmed") Is Nothing) Then
                    RaiseEvent Confirmed(Me, New EventArgs)
                End If
            ElseIf Not (postCollection(Me.NavigateBackButton.ClientID) Is Nothing And Me.Events.Item("NavigateBack") Is Nothing) Then
                RaiseEvent NavigateBack(Me, New EventArgs)
            End If
            'string postedValue = postCollection[postDataKey];
            Return False
        End Function

        Public Overridable Sub RaisePostDataChangedEvent() Implements System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent
        End Sub

    End Class
End Namespace
